<?php
/* @var $this MemberController */

$this->breadcrumbs=array(
	'Member',
);
?>
<?php if(!is_null($model)){?>
<div class="container white-bg" id="<?php echo $this->id.'-page'?>">
   <div class="member-info">
      <div class="caption font-opensans bold">Thông tin cá nhân</div>
      <ul >
         <li>
            <span class="label">Họ tên:</span>
            <span class="highlight bold"><?php echo $model->MemberName?></span>
         </li>
         <li>
            <span class="label">Email:</span>
            <span class="highlight bold"><?php echo $model->Email?></span>
         </li>
         <li>
            <span class="label">Số điện thoại:</span>
            <span class="highlight bold"><?php echo ($model->Mobile == '') ? 'Chưa cập nhật' : $model->Mobile;?></span>
         </li>
         <li>
            <span class="label">Giới tính:</span>
            <?php 
               switch($model->Gender){
                  case 0:
                     $gender = 'Nữ';
                     break;
                  case 1:
                     $gender = 'Nam';
                     break;
                  default:
                     $gender = 'Chưa cập nhật';
                     break;
               }
            ?>
            <span class="highlight bold"><?php echo  $gender;?></span>
         </li>
         <li>
            <a href="/cap-nhat-thong-tin-ca-nhan" class="btn btn-primary">Chỉnh sửa</a>
         </li>
      </ul>
      
   </div>
   
   <div class="main-content">
      <div class="left">
         <?php if(count($list_posted) > 0){?>
         <div class="list-news list-post">
            <div class="caption-label relative left"> 
               <em class="arrow half-arrow-down sprite absolute"></em>
               <span class="font-opensans">Các tin đã đăng</span>
            </div>
            <div class="clear"></div>
            <ul>
               <?php foreach($list_posted as $post_item){
                  $link = $post_item->linkDetail($post_item->post_id,$post_item->post_title);
                  ?>
               <li class="post-item" id="post-item-<?php echo $post_item->post_id?>">
                  <a href="<?php echo $link?>">
                     <p class="title <?php if($post_item->post_vip) echo 'highlight'?> bold font-opensans"><?php echo $post_item->post_title?></p>
                     <div class="img-wrap left">
                        <img src="<?php echo Yii::app()->params['path_image_post'].$post_item->post_avatar;?>" />
                     </div>
                  </a>
                  <div class="text">
                     <div class="summary">
                        <?php echo Str::cutString(Str::removeHTML($post_item->post_content),300)?>
                     </div>
                     <ul class="">
                        <li>
                           <span>Giá:</span>
                           <span class="highlight bold"><?php echo CVietnameseTools::readCurrentcy($post_item->post_price);?></span>
                        </li>
                        <li>
                           <span>Diện tích:</span>
                           <span class="highlight bold"><?php echo $post_item->post_area?> m²</span>
                        </li>
                        <li>
                           <?php 
                              $district = is_null($post_item->getRelated('district')) ? 'Chưa rõ' : $post_item->getRelated('district')->dis_name;
                              $province = is_null($post_item->getRelated('province')) ? 'Chưa rõ' : $post_item->getRelated('province')->prv_name;
                           ?>
                           <span>Quận/Huyện:</span>
                           <span class="highlight bold"><?php echo $district . ' ,' . $province?></span>
                        </li>  
                        <li class="right">
                           <span class="date"><?php echo date('d/m/Y',$post_item->post_date_update)?></span>
                        </li>                      
                     </ul>
                  </div>
                  <div class="clear"></div>
                  <div class="action">
                     <ul class="right">
                        <li><a class="btn btn-danger" style="padding: 3px; font-size: 12px;" href="javascript:void(0)" onclick="deletedPost(<?php echo $post_item->post_id?>)">Xóa</a></li>
                        <li><a class="btn btn-info" style="padding: 3px; font-size: 12px;" href="/chinh-sua-bai-dang/<?php echo $post_item->post_id?>">Chỉnh sửa</a></li>
                     </ul>
                  </div>
               </li>
               <?php }?>
            </ul>
            <div class="right">
            <?php 
               $pagination->render();
            ?>
            </div>
         </div>
         <?php }?>
      </div><!-- End left-content-->
      <div class="right">
         <div class="search-container">
            <div class="caption uppercase text-center relative font-opensans bold"><i class="sprite absolute icon-house"></i>Công cụ tìm kiếm</div>
            <?php 
               //Danh sach tinh thanh
               $list_province = array(0 => '-- Tỉnh/Thành Phố --'); // Danh sách các Tỉnh/Tp
               $province = new Province();
               $object = $province->findAll(array(
                  'order' => 'prv_order DESC, prv_name ASC',
               ));
               
               //Danh sach danh muc
               $list_category = array();
               $category = new Category();
               $all_cate = $category->getAll();
               $tree_cate = $category->getTree($all_cate);
               $tree_cate[0] = '-- Danh mục nhà đất --';
               if(count($object) > 0){
                  foreach($object as $item){
                     $list_province[$item->attributes['prv_id']] = $item->attributes['prv_name'];
                  }
               }
               
               //Danh sach quan huyen
               $model = new Post();
               $list_district = array(0 => '-- Quận/Huyện --');
               if($model->post_prv_id > 0){
                  $object = District::model()->getAllByPrvID($model->post_prv_id);
                  foreach($object as $item){
                     $list_district[$item['dis_id']] = $item['dis_name'];
                  }
               }
               
               //Danh sach cac du an
               $list_project = array(0 => '-- Dự án --');
               if($model->post_prv_id > 0){
                  $object = Project::model()->findAllByAttributes(array('prj_dis_id' => $model->post_dis_id));
                  foreach($object as $item){
                     $list_project[$item['prj_id']] = $item['prj_name'];
                  }
               }
               
               //Lua chon dien tich
               $list_area = array('0' => '-- Chọn mức giá --',
                                  '0,30' => 'Dưới 30 m2',
                                  '30,50' => '30 - 50 m2',
                                  '50,100' => '50 - 100 m2',
                                  '100,200' => '100 -200 m2',
                                  '200,500' => '200 - 500 m2',
                                  '500,1000' => '500 - 1000 m2',
                                  '1000' => 'Trên 1000 m2');
            ?>
            <?php $model = new Post();?>
            <div class="form-search" id="<?php echo Yii::app()->controller->id . '-' . Yii::app()->controller->action->id?>">
               <?php $form=$this->beginWidget('CActiveForm', array(
               	'id'=>Yii::app()->controller->id . '_' . Yii::app()->controller->action->id,
               	'enableAjaxValidation'=>false,
                  'enableClientValidation'=>false
               )); ?>
               
               <?php echo $form->errorSummary($model,'Kiểm tra lại các giá trị bạn vừa nhập vào'); ?>
               <div class="row">
                  <?php echo $form->dropDownList($model, 'post_cat_id',$tree_cate);?>
               </div>
               <div class="row">
                  <?php echo $form->dropDownList($model, 'post_prv_id',$list_province);?>
               </div>
               <div class="row">
                  <?php echo $form->dropDownList($model, 'post_dis_id',$list_district);?>
               </div>
               <div class="row">
                  <?php echo $form->dropDownList($model, 'post_prj_id',$list_project);?>
               </div>
               <div class="row">
                  <?php echo $form->dropDownList($model, 'post_area',$list_area);?>
               </div>
               <div class="row text-right relative">
                  <?php echo CHtml::submitButton('Tìm kiếm',array('id' => 'submit-search'))?>
               </div>   
               <?php $this->endWidget(); ?>
            </div> 
         </div> <!-- End search-container -->
      </div><!-- End right-content -->
   </div>
</div>
<script>
   $(document).ready(function(){
      $("#slide-show").responsiveSlides({      
        speed: 800,
        nav: true,
        pager: true,
        auto:true,
      });
      
      //Load district
      $("#Post_post_prv_id").change(function(){
         var prv_id = $(this).val();
         data = {'prv_id':prv_id};
         success = function(data){
            $("#Post_post_dis_id").html(data);
         }
         handleAjax('/district/SetDropListByPrvID','GET','',data,success);
      });
      
      //Load project
      $("#Post_post_dis_id").change(function(){
         var dis_id = $(this).val();
         data = {'dis_id':dis_id};
         success = function(data){
            $("#Post_post_prj_id").html(data);
         }
         handleAjax('/project/SetDropListByDisID','GET','',data,success);
      });
   });
</script>
<?php }?>